package com.qing.common_result.result;

import com.qing.common_result.result.CommonEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

@Data
@Getter
@Setter
@AllArgsConstructor
public class Result implements Serializable {


	private Integer code;

	private String message;

	private Object data;

	private Long timestamp = System.currentTimeMillis();

	public Result() {
	}

	public static Result setResultCode(CommonEnum resultCode) {
		Result result = new Result();
		result.setCode(resultCode.getCode());
		result.setMessage(resultCode.getMessage());
		return result;
	}


	public static Result success() {
		return setResultCode(ResultCode.SUCCESS);
	}

	public static Result success(Object data) {
		Result result = setResultCode(ResultCode.SUCCESS);
		result.setData(data);
		return result;
	}

	public static Result failure(CommonEnum resultCode) {
		return setResultCode(resultCode);
	}

	public static Result failure(CommonEnum resultCode, Object data) {
		Result result = setResultCode(resultCode);
		result.setData(data);
		return result;
	}

	public static Result failure(Integer code, String message, Object data) {
		Result result = new Result();
		result.setCode(code);
		result.setMessage(message);
		result.setData(data);
		return result;
	}

}
